package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonResponse;
import com.qingcheng.util.SmsUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

/**
 * 监听实现类  完成短信发送
 * @author 岳剑飞
 * @Company http://www.ithiema.com
 */
public class SmsMessageConsumer implements MessageListener {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${smsCode}")
    private String smsCode;  //短信模板编号

    @Value("${param}")
    private String param;   //短信参数

    @Override
    public void onMessage(Message message) {
        //1. 获取中间件 队列中的信息
        String jsonString=new String(message.getBody());
        Map<String,String> map = JSON.parseObject(jsonString, Map.class);
        //2. 获取手机号和 验证码
        String phone = map.get("phone");
        String code = map.get("code");
        System.out.println("手机号: "+phone+"，验证码: "+code);

        String param = this.param.replace("[value]", code);

        //调用阿里云通信 发送短信
      //CommonResponse commonResponse = smsUtil.sendSms(phone, smsCode, param);

    }
}
